-- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here
local map = vim.keymap.set

map("i", "jk", "<Esc>")
map("n", "<S-j>", "}")
map("n", "<S-k>", "{")

map("n", "<leader>l", function() end)
map("n", "<leader>L", function() end)

-- navigation
map("n", "<S-h>", "<C-w>h", { desc = "Go to Left Window", remap = true })
map("n", "<S-l>", "<C-w>l", { desc = "Go to Right Window", remap = true })
map("n", "<S-A-j>", "<C-w>j", { desc = "Go to Above Window", remap = true })
map("n", "<S-A-k>", "<C-w>k", { desc = "Go to Below Window", remap = true })

map("n", "<C-h>", "<cmd>bprevious<cr>", { desc = "Prev Buffer" })
map("n", "<C-l>", "<cmd>bnext<cr>", { desc = "Next Buffer" })

-- window management
map("n", "<c-\\>", "<C-W>v", { desc = "Split Window Right", remap = true })
map("n", "<leader>E", function()
  require("edgy").toggle()
end, { desc = "Toggle Sidebar (Edgy)", remap = true })

-- commenting
map({ "v" }, "<c-/>", "<cmd>normal gc<cr>", { desc = "Comment line" })
map({ "n" }, "<c-/>", "<cmd>normal gcc<cr>", { desc = "Comment line" })
-- map({"n", "v"}, "<c-_>", "<cmd>normal gcc<cr>", { desc = "Comment line" })

-- terminal
local lazyterm = function()
  Snacks.terminal()
end
map("n", "<leader>ft", lazyterm, { desc = "Terminal (Root Dir)" })
map("n", "<leader>fT", function()
  Snacks.terminal()
end, { desc = "Terminal (cwd)" })
map("n", "<c-`>", function()
  Snacks.terminal()
end, { desc = "Terminal (cwd)" })

-- coding
if vim.g.vscode then
  map({ "n", "v" }, "<leader>lf", function()
    require("vscode").action("editor.action.formatDocument")
  end, { desc = "Format" })
else
  map({ "n", "v" }, "<leader>lf", function()
    LazyVim.format({ force = true })
  end, { desc = "Format" })
end

-- diagnostic
map("n", "<leader>ld", vim.diagnostic.open_float, { desc = "Line Diagnostics" })
map("n", "ge", vim.diagnostic.open_float, { desc = "Line Diagnostics" })
